<html>
<head><meta charset="utf-8"><title>custom DST size/align/etc. as const fns? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom.20DST.20size.2Falign.2Fetc.2E.20as.20const.20fns.3F.html">custom DST size/align/etc. as const fns?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="166464418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom%20DST%20size/align/etc.%20as%20const%20fns%3F/near/166464418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom.20DST.20size.2Falign.2Fetc.2E.20as.20const.20fns.3F.html#166464418">(May 24 2019 at 15:45)</a>:</h4>
<p>In <a href="https://github.com/rust-lang/rust/pull/61114#issuecomment-495676864" target="_blank" title="https://github.com/rust-lang/rust/pull/61114#issuecomment-495676864">https://github.com/rust-lang/rust/pull/61114#issuecomment-495676864</a> <span class="user-mention" data-user-id="120791">@RalfJ</span> wrote:</p>
<blockquote>
<p>The desired interaction with unsized types is not really clear. One custom DST are a thing, I doubt we want Stacked Borrows to run the arbitrary user code to compute the size...</p>
</blockquote>
<p>While I can't comment on the stacked borrows interaction, it made me wonder whether the hooks provided by custom DSTs (size_of_val in this case, but others too) should be const fns? That would make them reasonable to evaluate in a stacked borrows, I'd think. It is somewhat close to the "using const fn to enforce code to be well-behaved" school of design which I've never been a big fan of, but it really doesn't seem so unreasonable to say that <code>size_of_val</code> should always be const fn.</p>



<a name="166465692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom%20DST%20size/align/etc.%20as%20const%20fns%3F/near/166465692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom.20DST.20size.2Falign.2Fetc.2E.20as.20const.20fns.3F.html#166465692">(May 24 2019 at 15:58)</a>:</h4>
<p>that is an interesting idea!</p>



<a name="166465711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom%20DST%20size/align/etc.%20as%20const%20fns%3F/near/166465711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/custom.20DST.20size.2Falign.2Fetc.2E.20as.20const.20fns.3F.html#166465711">(May 24 2019 at 15:58)</a>:</h4>
<p>it'd still be a huge pain to "call back" to the interpreter in the middle of, say, doing a type-based traversal of some value</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>